package maiyatian.videolive;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.xutils.x;

import maiyatian.videolive.common.Utils;

/**
 * Created by 王中阳 on 2016/5/9.
 */
public class IFragment extends Fragment {
    public static final String TAG = IFragment.class.getSimpleName();
    private boolean injected = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        injected = true;
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (!injected) {
            x.view().inject(this, this.getView());
        }
    }

    public void skip(Context mContext, Activity fromAct, Activity toAct, IFragment fragment) {
        Intent intent = new Intent();
        intent.setClass(fromAct, toAct.getClass());
        intent.putExtra(IActivity.PAGETO, fragment.TAG);
        mContext.startActivity(intent);
    }


    private String getTime(long time) {
        long dTime = Math.abs(System.currentTimeMillis() / 1000 - time);// 时间差
        long minute = dTime / 60;
        long hours = minute / 60;
        if (minute < 25)
            return getResources().getString(R.string.time_show);
        else if (minute < 60)
            return String.format(getResources().getString(R.string.time_show_minute), minute);
        else if (hours < 24)
            return String.format(getResources().getString(R.string.time_show_hours), hours);
        else
            return Utils.getTime(time);
    }
}
